package com.hellowx.qydcdev.controller;

import com.hellowx.qydcdev.annotaion.RequiredToken;
import com.hellowx.qydcdev.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * Created on 2022/1/14.
 *
 * @author Hello WX
 */
@Api(tags = "统计图表模块")
@RestController
@RequestMapping("/echarts")
public class EchartsController {

    @Resource
    private OrderService orderService;

    @ApiOperation("统计各类订单数量")
    @GetMapping("/variousOrdersPie")
    @RequiredToken
    public ResponseEntity<List<Map<String, Object>>> variousOrdersPie(HttpServletRequest request){
        List<Map<String, Object>> peiData = orderService.variousOrdersPie(request);
        return ResponseEntity.ok(peiData);
    }

    @ApiOperation("按月统计订单数量和金额")
    @GetMapping("/countOrderByMonth")
    @RequiredToken
    public ResponseEntity<Map<String, Object>> countOrderByMonth(HttpServletRequest request){
        Map<String, Object> data = orderService.countOrderByMonth(request);
        return ResponseEntity.ok(data);
    }

    @ApiOperation("按天统计订单数量和金额")
    @GetMapping("/countOrderByDay")
    @RequiredToken
    public ResponseEntity<Map<String, Object>> countOrderByDay(HttpServletRequest request){
        Map<String, Object> data = orderService.countOrderByDay(request);
        return ResponseEntity.ok(data);
    }

    @ApiOperation("统计热销Top8的商品")
    @GetMapping("countGoodsOrderTop8")
    @RequiredToken
    public ResponseEntity<Map<String, Object>> countGoodsOrderTop8(HttpServletRequest request){
        Map<String, Object> map = orderService.countGoodsOrderTop8(request);
        return ResponseEntity.ok(map);
    }
}
